var app = getApp()
var appData = app.globalData
Page({
    data: {
        isShowSubmenu: [false, false, false],
        userInfo: ''
    },

    showAndHideSubmenu: function (e) {
        var index = Number(e.currentTarget.id)
        var isShowArray = [];
        for (var i = 0; i < this.data.isShowSubmenu.length; i++) {
            isShowArray.push(index == i ? true : false);
        }
        this.setData({ isShowSubmenu: isShowArray })
    },

    onLoad: function (options) {
        console.log('appData.shopInfo===',appData.shopInfo)
        this.setData({ userInfo: appData.shopInfo })
        wx.setNavigationBarTitle({
            title: this.data.userInfo.shopInfo.shop + '后台',
        })
    },

    onShow: function (opt) {
        console.log('生命周期函数--监听页面显示opt', opt)
        var appUser = appData.shopInfo
        console.log('this.data', this.data)
        if (appUser.shopInfo.userid != this.data.userInfo.shopInfo.userid) {
            console.log('开始重载')
            this.onLoad()
        }
    },

    myInfo: function () {
        this.goto('02admin/00shop/shopSet')
    },

    toWaiter: function () {
        this.goto('02admin/00waiter/waiter')
    },

    toTableClass: function () {
        this.goto('02admin/02tableClass/tableClass')
    },

    toTable: function () {
        this.goto('02admin/03table/table')
    },

    setGoodsClass: function () {
        this.goto('02admin/10goodsCate/goodsCate')
    },

    shelvesGoods: function () {
        if (appData.loginMode == 'boss') {
            this.goto('02admin/12goodsShelves/goodsShelves')
        } else {
            app.toast('需要掌柜登录才能操作')
        }
    },

    sellingGoods: function () {
        this.goto('02admin/13sellingGoods/sellingGoods')
    },

    warehouseGoods: function () {
        this.goto('02admin/14warehouseGoods/warehouseGoods')
    },

    goodsList: function () {
        this.goto('02admin/15goodsList/goodsList')
    },

    toWechatClass: function () {
        this.goto('03setup/00aboutQzg/aboutQzg')
    },

    toHelpClass: function () {
        this.goto('03setup/01helpFeedback/helpFeedback')
    },

    setWifiPrinter: function () {
        if (appData.loginMode == 'boss') {
            this.goto('03setup/02printer/printerSet')
        } else {
            app.toast('需要掌柜登录才能操作')
        }
    },
    report:function(){
            this.goto('02admin/16report/report')
    },
    toSetPrinter: function () {
        if (appData.loginMode == 'boss') {
            this.goto('03setup/02setPrinter/setPrinter')
        } else {
            app.toast('需要掌柜登录才能操作')
        }
    },

    setOut: function () {
        appData.shopInfo = ''
        this.goto('00login/login')
    },

    goto:function(path){
        wx.navigateTo({
            url: '/pages/'+path
        })
    },
    //用户点击右上角分享
    onShareAppMessage: function () {
        var userInfoStr = JSON.stringify(this.data.loginGuestInfo)
        return {
            title: appData.guestInfo.name + '邀请您来【桥掌柜】当掌柜',
            path: '/pages/00login/login?str=' + userInfoStr
        }
    }
})
